package com.fairytask.ui.login
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.resource.QueueLoader;
	
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;

	/**
	 * 登陆场景控制 
	 * @author hanjy
	 */	
	public class LoginStage extends Sprite
	{
		public static var instance 	:LoginStage;
		
		private var _loginBg	:Bitmap;	//登陆背景
		private var _animat	:MovieClip;
		
		public static function getInstance():LoginStage
		{
			if(instance==null)
			{
				instance	=	new LoginStage();
			}
			return instance;
		}
			
		
		public function LoginStage()
		{
			super();
			initGUI();
		}
		
		private function initGUI():void
		{
			//加载背景图
			QueueLoader.StartLoad(ResConfig.imgResPath+"login/login.jpg", bgLoaded);
		}
		/**
		 * 背景图加载完毕
		 * @param evt
		 */
		private function bgLoaded(val:Bitmap):void
		{
			_loginBg	=	val;
			//_loginBg.smoothing	=	true;
			_loginBg.x	=	-220;
			_loginBg.y	=	-150;
			addChildAt(_loginBg,0);
			//加载柳条
			//QueueLoader.StartLoad(ResConfig.swfResPath+"loginAnimat.swf", animatLoaded);
		}
		
		/**
		 * 显示登陆 
		 * 
		 */
		public function showLogin():void
		{
			show();
			LoginUI.getInstance().show();
		}
		
		/**
		 * 隐藏登陆 
		 */
		public function hideLogin():void
		{
			LoginUI.getInstance().hide();
		}
		/**
		 * 添加
		 * @param evt
		 */
		private function animatLoaded(val:MovieClip):void
		{
			_animat	=	val;
			addChildAt(_animat,1);
		}
		/**
		 * 显示登陆场景 
		 */
		public function show():void
		{
			GameStage.uiSpace.addBack(this);
		}
		/**
		 * 移除显示场景 
		 */
		public function hide():void
		{
			if(this.parent!=null)
			{
				this.parent.removeChild(this);
			}
			GameStage.uiSpace.clearLogin();
		}
	}
}